package org.example.erp.controller;

import org.example.erp.domain.WarehouseArea;
import org.example.erp.service.WarehouseAreaService;
import org.example.erp.service.impl.WarehouseAreaServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class WarehouseAreaController {
    @Autowired
    WarehouseAreaServiceImpl warehouseAreaService;


    @GetMapping("/warehouseArea/find")
    public DataResult findwarehouseArea(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
                                    @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                    @RequestParam Integer warehouseId,
                                    @RequestParam (required = false) String warehouseAreaName
    ){
        return DataResult.success(warehouseAreaService.findwarehousearea(currentPage,pageSize,warehouseId,warehouseAreaName));
    }


    @PostMapping("/warehouseArea/insert")
    public DataResult insertwarehouseArea(@RequestBody WarehouseArea warehouseArea){
        return DataResult.success(warehouseAreaService.save(warehouseArea));
    }

    @PutMapping("/warehouseArea/update")
    public DataResult updatewarehouseArea( @RequestBody WarehouseArea warehouseArea){
        return DataResult.success(warehouseAreaService.updateById(warehouseArea));
    }

    @DeleteMapping("/warehouseArea/delete")
    public DataResult datelewarehouseArea(@RequestBody List<Integer> logIds){
        return DataResult.success(warehouseAreaService.removeByIds(logIds));
    }
}
